In [ ]:
using Plots
using Random
using Distributions
using Statistics
using LaTeXStrings
In [ ]:
function Binomiali(N,p,nn) ### Numero de pruebas ##nn= numero de intentos
options = [1, 0]
probabilities = [p,1-p] # Adjust the probabilities as needed
# Create a random sample of indices using the probabilities
sampled_indices = rand(Categorical(probabilities),nn,N)
# Map the sampled indices to the options array
dn = options[sampled_indices]
n=zeros(nn,N)
for i in 1:N
n[:,i]=sum(dn[:,1:i],dims=2)
end
return n
end
Out[ ]:
Binomiali (generic function with 1 method)
Modelo SIR Estocastico binomial¶
In [ ]:
tf=100
S,I,R,ts,tps=SIReb(997,3,100,1/2,1/2,1000,100);
mt=mean(ts,dims=1)
ms=mean(S,dims=1)
sds=std(S,dims=1)
mi=mean(I,dims=1)
sdi=std(I,dims=1)
mr=mean(R,dims=1)
sdr=std(R,dims=1)
### tiempo
mean(tps)
std(tps)
plot(ts,S,color="blue",label="",alpha=0.02, title="Evolución Modelo SIR, esocastico binomial")
plot!(ts,I,color="red",label="",alpha=0.02)
plot!(ts,R,color="green",label="",alpha=0.02)
#plot!(mt',ms', color="blue",label=L"\langle S \rangle",lw=2)
#plot!(mt',mi', color="red",label=L"\langle I \rangle",lw=2)
#plot!(mt',mr', color="green",label=L"\langle R \rangle",lw=2)
#plot!(mt',sds', label=L"\sigma(S)",lw=2)
Out[ ]:
In [ ]:
mean(tps)
Out[ ]:
0.16177462099999995
In [ ]:
tf=100
S,I,R,ts,tps=SIReb(990,10,100,1/20,1/2,1000,100);
plot(ts,S,color="blue",label="",alpha=0.01)
plot!(ts,I,color="red",label="",alpha=0.01)
plot!(ts,R,color="green",label="",alpha=0.01)
mt=mean(ts,dims=1)
ms=mean(S,dims=1)
sds=std(S,dims=1)
mi=mean(I,dims=1)
sdi=std(I,dims=1)
mr=mean(R,dims=1)
sdr=std(R,dims=1)
### tiempo
mean(tps)
std(tps)
plot!(mt',ms', color="blue",label=L"\langle S \rangle",lw=2)
plot!(mt',mi', color="red",label=L"\langle I \rangle",lw=2)
plot!(mt',mr', color="green",label=L"\langle R \rangle",lw=2)
#plot!(mt',sds', label=L"\sigma(S)",lw=2)
Out[ ]:
In [ ]:
S,I,R,ts,tps=SIReb(998,1,100,0.1,0.2,1000,100);
plot(ts,S,color="blue",label="",alpha=0.02)
plot!(ts,I,color="red",label="",alpha=0.02)
plot!(ts,R,color="green",label="",alpha=0.02)
mt=mean(ts,dims=1)
ms=mean(S,dims=1)
sds=std(S,dims=1)
mi=mean(I,dims=1)
sdi=std(I,dims=1)
mr=mean(R,dims=1)
sdr=std(R,dims=1)
### tiempo
mean(tps)
std(tps)
plot!(mt',ms', color="blue",label=L"\langle S \rangle",lw=2)
plot!(mt',mi', color="red",label=L"\langle I \rangle",lw=2)
plot!(mt',mr', color="green",label=L"\langle R \rangle",lw=2)
#plot!(mt',sds', label=L"\sigma(S)",lw=2)
Out[ ]:
Modelo SIR Doob-Gillspie¶
$$S,I \rightarrow (S-1,I+1) \\ P=\beta \frac{S I}{N}$$ $$I,R \rightarrow (I-1,R+1) \\ P=\gamma I$$
In [ ]:
S0=997
I0=3
tf=100
NN=100
β=1/2
γ=1/2
S1,I1,R1,ts1,tps1=SIRGB1(S0,I0,tf,γ,β,NN);
p=plot()
for j in 1:NN
plot!(ts1[j]',S1[j]',label="",color="blue",lw=2,title="Evolución Modelo SIR, esocastico Doob-Gillspie",alpha=0.07)
plot!(ts1[j]',I1[j]',label="",color="red",lw=2,alpha=0.07)
plot!(ts1[j]',R1[j]',label="",color="green",lw=2,alpha=0.07)
end
display(p)
In [ ]:
S0=990
I0=10
tf=100
NN=100
β=1/2
γ=1/20
S1,I1,R1,ts1,tps1 = SIRGB1(S0,I0,tf,γ,β,NN)
p=plot()
for j in 1:NN
plot!(ts1[j]',S1[j]',label="",color="blue",lw=2,title="Evolución Modelo SIR, esocastico Doob-Gillspie",alpha=0.07)
plot!(ts1[j]',I1[j]',label="",color="red",lw=2,alpha=0.07)
plot!(ts1[j]',R1[j]',label="",color="green",lw=2,alpha=0.07)
end
display(p)
mean(tps)
std(tps)